using System;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Linq.Expressions;

namespace OurWedding1.Models
{ 
    public class GuestSideRepository : IGuestSideRepository
    {
        readonly WeddingEntities _context = new WeddingEntities();

        public IQueryable<GuestSide> All
        {
            get { return _context.GuestSides; }
        }

        public IQueryable<GuestSide> AllIncluding(params Expression<Func<GuestSide, object>>[] includeProperties)
        {
            IQueryable<GuestSide> query = _context.GuestSides;
            foreach (var includeProperty in includeProperties) {
                query = query.Include(includeProperty);
            }
            return query;
        }

        public GuestSide Find(int id)
        {
            return _context.GuestSides.Find(id);
        }

        public void InsertOrUpdate(GuestSide guestside)
        {
            if (guestside.GuestSideId == default(int)) {
                // New entity
                _context.GuestSides.Add(guestside);
            } else {
                // Existing entity
                _context.Entry(guestside).State = EntityState.Modified;
            }
        }

        public void Delete(int id)
        {
            var guestside = _context.GuestSides.Find(id);
            _context.GuestSides.Remove(guestside);
        }

        public void Save()
        {
            _context.SaveChanges();
        }

        public void Dispose() 
        {
            _context.Dispose();
        }
    }

    public interface IGuestSideRepository : IDisposable
    {
        IQueryable<GuestSide> All { get; }
        IQueryable<GuestSide> AllIncluding(params Expression<Func<GuestSide, object>>[] includeProperties);
        GuestSide Find(int id);
        void InsertOrUpdate(GuestSide guestside);
        void Delete(int id);
        void Save();
    }
}